<%@page import="routeEntity.Route" %>
<%@page import="java.util.List" %>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.css">
    <script src="jQuery/jquery-3.3.1.js"></script>
    <script src="bootstrap-3.3.7-dist/js/bootstrap.js"></script>
    <script src="js/jquery.validate.js"></script>
    <link rel="stylesheet" href="css/admin.css">
    <title></title>
    <style type="text/css">
        label {
            font-size: 20px;
            color: red;
            margin-right: -8px;
        }
    </style>
    <script type="text/javascript">
        function submit_sure() {
            var gnl = confirm("确定删除该路线吗？");
            if (gnl === true) {
                return true;
            } else {
                return false;
            }
        }

        function Value(Rid, Rname, fromStation, fromTime, toStation, toTime, seatPrice, seatNumber) {
            $("#Rid1").val(Rid);
            $("#Rname1").val(Rname);
            $("#fromStation1").val(fromStation);
            $("#fromTime1").val(fromTime);
            $("#toStation1").val(toStation);
            $("#toTime1").val(toTime);
            $("#seatPrice1").val(seatPrice);
            $("#seatNumber1").val(seatNumber);
        }

        function go(num) {
            document.getElementById("cp").value = num;
            document.spform.submit();	// 表单提交
        }

        $(document).ready(function () {
            $("#resetRoute").validate({
                rules: {
                    Rname: {
                        required: true
                    },
                    fromStation: {
                        required: true
                    },
                    toStation: {
                        required: true
                    },
                    fromTime: {
                        required: true
                    },
                    toTime: {
                        required: true
                    },
                    seatNumber: {
                        required: true
                    },
                    seatPrice: {

                        required: true
                    }
                },
                messages: {
                    Rname: {
                        required: "*"
                    },
                    fromStation: {
                        required: "*"
                    },
                    toStation: {
                        required: "*"
                    },
                    fromTime: {
                        required: "*"
                    },
                    toTime: {
                        required: "*"
                    },
                    seatNumber: {
                        required: "*"
                    },
                    seatPrice: {
                        required: "*"
                    }
                }
            })
        });
        $(document).ready(function () {
            $("#addRouteForm").validate({
                rules: {
                    Rname: {
                        required: true
                    },
                    fromStation: {
                        required: true
                    },
                    toStation: {
                        required: true
                    },
                    fromTime: {
                        required: true
                    },
                    toTime: {
                        required: true
                    },
                    seatNumber: {
                        required: true
                    },
                    seatPrice: {

                        required: true
                    }
                },
                messages: {
                    Rname: {
                        required: "*"
                    },
                    fromStation: {
                        required: "*"
                    },
                    toStation: {
                        required: "*"
                    },
                    fromTime: {
                        required: "*"
                    },
                    toTime: {
                        required: "*"
                    },
                    seatNumber: {
                        required: "*"
                    },
                    seatPrice: {
                        required: "*"
                    }
                }
            })
        });
    </script>
</head>
<body>
<%!
    public static final String URL = "adminRoute.jsp";
%>
<!-- 修改路线模态框开始 -->
<form action="AdminResetRoute" method="post" id="resetRoute">
    <input type="hidden" name="Rid" value="" id="Rid1">
    <div class="modal fade" id="resetModal" tabindex="-1"
         role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">&times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel">修改车次</h4>
                </div>
                <div class="modal-body">
                    <div class="modal-body">
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">车次名
															</span> <input type="text" class="form-control"
                                                                           value="" id="Rname1" name="Rname">
                        </div>
                        <br/>
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">始发站
															</span> <input type="text" class="form-control"
                                                                           value="" id="fromStation1" name="fromStation">
                        </div>
                        <br/>
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">终点站
															</span> <input type="text" class="form-control"
                                                                           value="" id="toStation1" name="toStation">
                        </div>
                        <br/>
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">发车时间
															</span> <input type="datetime-local" class="form-control"
                                                                           value="" id="fromTime1" name="fromTime">
                        </div>
                        <br/>
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">到达时间
															</span> <input type="datetime-local" class="form-control"
                                                                           value="" id="toTime1" name="toTime">
                        </div>
                        <br/>
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">座位数
															</span> <input type="number" class="form-control"
                                                                           value="" id="seatNumber1" name="seatNumber">
                        </div>
                        <br/>
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">车票价格
															</span> <input type="number" class="form-control"
                                                                           value="" id="seatPrice1" name="seatPrice">
                        </div>
                        <br/>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default"
                                data-dismiss="modal">关闭
                        </button>
                        <button type="submit" class="btn btn-primary">确认修改
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<!-- 修改路线模态框结束 -->
<!-- 添加路线模态框开始 -->
<form action="AddRoute" method="post" id="addRouteForm">
    <div class="modal fade" id="addRouteModal" tabindex="-1"
         role="dialog" aria-labelledby="myModalLabel"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"
                            aria-hidden="true">&times;
                    </button>
                    <h4 class="modal-title" id="myModalLabel1">添加车次</h4>
                </div>
                <div class="modal-body">
                    <div class="modal-body">
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">车次名
															</span> <input type="text" class="form-control"
                                                                           placeholder="请输入车次" name="Rname">
                        </div>
                        <br/>
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">始发站
															</span> <input type="text" class="form-control"
                                                                           placeholder="请输入始发车站" name="fromStation">
                        </div>
                        <br/>
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">终点站
															</span> <input type="text" class="form-control"
                                                                           placeholder="请输入终点车站" name="toStation">
                        </div>
                        <br/>
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">发车时间
															</span> <input type="datetime-local" class="form-control"
                                                                           placeholder="请输入发车时间" name="fromTime">
                        </div>
                        <br/>
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">到达时间
															</span> <input type="datetime-local" class="form-control"
                                                                           placeholder="请输入到达时间" name="toTime">
                        </div>
                        <br/>
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">座位数
															</span> <input type="number" class="form-control"
                                                                           placeholder="请输入座位数量" name="seatNumber">
                        </div>
                        <br/>
                        <div class="input-group"
                             style="height: 10px; width: 450px;">
															<span class="input-group-addon" style="width: 100px;">车票价格
															</span> <input type="number" class="form-control"
                                                                           placeholder="请输入票价" name="seatPrice">
                        </div>
                        <br/>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default"
                                data-dismiss="modal">关闭
                        </button>
                        <button type="submit" class="btn btn-primary">添加
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<!-- 添加路线模态框结束 -->
<div class="snow">
    <div class="container">
        <!--logo导航开始-->
        <div class="head">
            <a class="ht"><img src="images/logo.jpg"/></a>
            <div class="hs">
            <span><button type="button" class="btn btn-default btn-lg">
                            <a href="#"><span class="glyphicon glyphicon-user"></span></a>
                            </button>
                <a href="index.jsp"><button id="hb" class="btn btn-primary btn-lg">退出管理</button></a>
            </span>
            </div>
        </div>
        <!--logo导航结束-->
        <!--导航列表开始-->
        <div class="navi-w">
            <div class="navi">
                <ul class="navi">
                    <li>
                        <a href="admin.jsp">首页</a>
                    </li>
                    <li class="on">
                        <a href="adminRoute.jsp">车次管理</a>
                    </li>
                    <li>
                        <a href="adminUser.jsp">用户管理</a>
                    </li>
                </ul>
            </div>
        </div>
        <!--导航列表结束-->
        <div id="con" class="container">
            <form action="AdminQueryRoute" method="post">
                <table align="center" style="width:80%;padding: 100px;margin-bottom: 20px;font-size: 18px;">
                    <tr>
                        <td><strong>始发站</strong></td>
                        <td><input class="form-control" style="width:180px; height:35px;" type="text" name="fromStation" placeholder="请输入始发车站"></td>
                        <td><strong>终点站</strong></td>
                        <td><input class="form-control" style="width:180px; height:35px;" type="text" name="toStation" placeholder="请输入终点站"></td>
                        <td><strong>出发日</strong></td>
                        <td><input class="form-control" style="width:180px; height:35px;" type="date" name="fromTime"></td>
                        <td style="width: 300px">
                            <button type="submit" class="btn btn-default">查询</button>
                            <button type="button" class="btn btn-default"
                                    data-toggle="modal" data-target="#addRouteModal">添加车次
                            </button> <!-- 模态框（Modal） -->
                        </td>
                </table>
            </form>
            <table style="font-size: 16px; " class="table table-bordered ">
                <tr>
                    <th>车次ID</th>
                    <th>路线名</th>
                    <th>始发站</th>
                    <th>出发时间</th>
                    <th>终点站</th>
                    <th>到达时间</th>
                    <th>票价</th>
                    <th>票数</th>
                    <th>修改</th>
                    <th>删除</th>
                </tr>
                <%
                    List<Route> list;
                    int currentPage = 1;    // 为当前所在的页，默认在第1页
                    int lineSize = 7;        // 每次显示的记录数
                    int allRecorders = 0;    // 表示全部的记录数
                    int pageSize = 10;        // 表示全部的页数（尾页）
                    try {
                        currentPage = Integer.parseInt(request.getParameter("cp"));
                    } catch (Exception e) {
                    }

                    int number = (currentPage - 1) * lineSize;
                    if (session.getAttribute("routeList") != null) {
                        list = (List) session.getAttribute("routeList");
                        if (list.size() > 0) {
                            Route route;
                            try {
                                for (int i = number; i < (number + lineSize); i++) {
                                    route = list.get(i);
                %>
                <form action="DeleteRoute" method="post" onsubmit="return submit_sure()">
                    <input type="hidden" name="Rid" value="<%=list.get(i).getRid() %>">
                    <tr>
                        <td><%= route.getRid() %>
                        </td>
                        <td><%= route.getRname() %>
                        </td>
                        <td><%= route.getFromStation() %>
                        </td>
                        <td><%= route.getFromTime() %>
                        </td>
                        <td><%= route.getToStation() %>
                        </td>
                        <td><%= route.getToTime() %>
                        </td>
                        <td><%= route.getSeatPrice() %>元
                        </td>
                        <td><%= route.getSeatNumber() %>
                        </td>
                        <td>
                            <button id="reset" type="button" class="btn btn-default"
                                    data-toggle="modal" data-target="#resetModal" onclick="Value( '<%=list.get(i).getRid()%>' , '<%=list.get(i).getRname()%>' , '<%=list.get(i).getFromStation()%>' , '<%=list.get(i).getFromTime()%>','<%=list.get(i).getToStation()%>','<%=list.get(i).getToTime()%>','<%=list.get(i).getSeatPrice()%>','<%=list.get(i).getSeatNumber()%>')">修改
                            </button>
                        </td>
                        <td><input type="submit" value="确认删除" style="color: red;border-radius:3px;font-weight: 400"></td>
                    </tr>
                </form>
                <%
                                }
                            } catch (Exception e) {
                            }
                        }
                    }
                %>
            </table>
            <div style="width: 98%;height: 75px;position: absolute;bottom: -4px;text-align: center">
                <form class="form1" name="spform" action="<%=URL%>" method="get" style="font-size: 20px;">
                    <input type="button" value="首页" onclick="go(1)" style="border-radius:2px;">
                    <input type="button" value="上一页" onclick="go(<%=currentPage-1%>)" style="border-radius:2px;">
                    <input type="button" value="下一页" onclick="go(<%=currentPage+1%>)" style="border-radius:2px;">
                    <input type="button" value="尾页" onclick="go(<%=pageSize%>)" style="border-radius:2px;">

                    跳转到第<select name="selcp" onchange="go(this.value)">
                    <%for (int x = 1; x <= 4; x++) {%>
                    <option value="<%=x%>" <%=x == currentPage ? "SELECTED" : ""%>><%=x%>
                    </option>
                    <%}%>
                </select>页

                    <input id="cp" type="hidden" name="cp" value="1">
                </form>
            </div>
        </div>
        <!--底部-->
        <div class="foot">
            <p>
                <a href="#">关于我们 &nbsp;</a>|
                <a href="#">&nbsp;网站声明 </a>
            </p>
            <p>版权所有©2018 &nbsp; 计科普通一班 &nbsp;第五小组</p>
        </div>
    </div>
</div>
</body>
</html>